package com.jinlejia.feedback.weight;

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jinlejia.feedback.R;

import java.util.Locale;

public class FbLookAllCountView extends LinearLayout {
    public FbLookAllCountView(Context context) {
        this(context,null);
    }

    public FbLookAllCountView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public FbLookAllCountView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs, defStyleAttr);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public FbLookAllCountView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context, attrs, defStyleAttr);
    }

    private TextView lookTextView;

    private int countValue;
    private TYPE typeEnum;
    private void init(Context context, AttributeSet attrs, int defStyleAttr){
        LayoutInflater.from(context).inflate(R.layout.fb_weight_all_count_layout, this, true);
        lookTextView = findViewById(R.id.lookTextView);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.FbLookAllCountView);
        countValue = typedArray.getInteger(R.styleable.FbLookAllCountView_fbCountValue,0);
        int type = typedArray.getInteger(R.styleable.FbLookAllCountView_fbType,0);
        typedArray.recycle();
        if (type==0){
            setTypeAll();
        }else {
            setTypeCount(countValue);
        }
    }

    public void setTypeAll(){
        typeEnum = TYPE.ALL;
        lookTextView.setText("查看全部跟进");
    }

    public void setTypeCount(int countValue){
        this.countValue = countValue;
        typeEnum = TYPE.COUNT_VALUE;
        lookTextView.setText(String.format(Locale.CHINESE,"查看%d条回复", countValue));
    }

    public enum TYPE{
        ALL(0),
        COUNT_VALUE(1);
        private int valueCount;
        TYPE(int i) {
            valueCount = i;
        }

        public int getValueCount() {
            return valueCount;
        }
    }
}
